# --*-- coding:utf8 --*--

class dataNode():
    def __init__(self, value, datalen, start=None, end=None) -> None:
        self.son = dict()
        self.value = value
        self.version = None
        self.changeV = False
        self.datalen = datalen
        self.start = start
        self.end = end
        self.caseDetail = [0] * datalen  # 总数, 成功, 失败, 执行, 轮询, 缺陷

    def updateNode(self, args, type=None):
        """
        type: define 1=insertCaseDetail, 2=updateByVersion, 3=updateByOther
        """
        if not type:
            raise Exception("Type is Error")
        if 1 == type:
            return self._insertCaseDetail(args)
        elif 2 == type:
            return self._updateByVersion(args)
        elif 3 == type:
            return self._updateByVersionUp(args)
        else:
            return self._updateByOther(args)

    def _insertCaseDetail(self, args):
        assert (len(args) == self.datalen)
        for _, detail in enumerate(args, 0):
            self.caseDetail[_] = detail
            yield self.caseDetail[_]

    def _updateByVersion(self, args):
        assert (len(args) == self.datalen)
        for _, detail in enumerate(args, 0):
            temp, self.caseDetail[_] = detail - self.caseDetail[_], detail
            yield temp

    def _updateByVersionUp(self, args):
        assert (len(args) == self.datalen)
        self.changeV = True
        for _, detail in enumerate(args, 0):
            self.caseDetail[_] = self.caseDetail[_] + detail
            yield detail

    def _updateByOther(self, args):
        assert (len(args) == self.datalen)
        for _, detail in enumerate(args, 0):
            self.caseDetail[_] = detail + self.caseDetail[_]
            yield detail

# class dataNodeforBar(dataNode):
#     def __init__(self, value, datalen, start = None, end = None, catag = catagforyear) -> None:
#         super().__init__(value, datalen)

#         #开始，结束日期传入2020, 2021,
#         if catag == catagforyear:
#             self.caseDetailforBar = {year: dataNode() for year in range(int(end[:4]),  int(start[:4])+1)}
#         else:
#             #TODO
#             pass
